from src.world import *
import time
import threading

world = World()
for i in range(20):
    world.add_guy()
#guy_property = world.guy_list[0].get_guy_property() #初始化角色属性列表
#print(guy_property)
pause = 0

def main():
    global pause
    while 1:
        if pause == 0:
            world.timemoves(50)
            print('timemove')
        time.sleep(1)

def keyin():
    global pause
    while 1:
        cmd = input('>>>')
        if 1 == 0:
            try:
                keyin2(cmd)
            except:
                print("无效输入")
        else:
            keyin2(cmd)

def keyin2(cmd):
    global pause
    if cmd == '':
        if pause == 0:
            print('暂停')
        else:
            print('继续')
        pause = 1 - pause
        print('change')
    elif 'addg' in cmd:
        world.add_guy()
    elif 'ckg' in cmd[:3]:
        world.check_guy()
    elif 'test' in cmd[:4]:
        world.test()
    elif 'save' in cmd[:4]:
        world.save()  # TODO 多存档
    elif 'load' in cmd[:4]:
        world.load()  #
thread_list =[]
thread1 = threading.Thread(target = main, args = ())
thread_list.append(thread1)
thread2 = threading.Thread(target = keyin, args = ())
thread_list.append(thread2)
for i in thread_list:
    i.start()
for i in thread_list:
    i.join()

